package com.tianyang.yukuaifu.module.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.tianyang.yukuaifu.R;
import com.tianyang.yukuaifu.business.main.provider.MainOpenProvider;
import com.tianyang.yukuaifu.common.interfaces.UrlConstants;
import com.tianyang.yukuaifu.module.dialog.interfaces.IGlobalListener;
import com.tianyang.yukuaifu.module.specialunit.OnClickableSpanListener;
import com.tianyang.yukuaifu.module.specialunit.SimplifySpanBuild;
import com.tianyang.yukuaifu.module.specialunit.unit.SpecialClickableUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Description：隐私政策
 * Created by 薛勇军 on 2021/7/31.
 */

public class PrivacyDialog extends Dialog {

    @BindView(R.id.contentTv)
    TextView contentTv;

    private Context mContext;

    private IGlobalListener globalListener;

    public void setGlobalListener(IGlobalListener globalListener) {
        this.globalListener = globalListener;
    }

    public PrivacyDialog(Context context) {
        super(context, R.style.dialog_normal);
        setContentView(R.layout.view_privacy_dialog);
        ButterKnife.bind(this);
        this.mContext = context;
        setCancelable(false);

        SpecialClickableUnit clickableUnit = new SpecialClickableUnit(new OnClickableSpanListener() {
            @Override
            public void onClick(TextView tv, String clickText) {
                MainOpenProvider.getInstance().openBrowserX5Activity(mContext, "《隐私政策》", UrlConstants.PRIVACY_POLICY);
            }
        });
        clickableUnit.setSpecialText("《隐私政策》");
        clickableUnit.setNormalTextColor(ContextCompat.getColor(mContext, R.color.color_base));
        clickableUnit.setPressTextColor(ContextCompat.getColor(mContext, R.color.base_press_color));

//        SpecialClickableUnit clickableUnit2 = new SpecialClickableUnit(new OnClickableSpanListener() {
//            @Override
//            public void onClick(TextView tv, String clickText) {
//                MainOpenProvider.getInstance().openBrowserX5Activity(mContext, "服务商合规展业规范", UrlConstants.AGREEMENT);
//            }
//        });
//        clickableUnit2.setSpecialText("《服务商合规展业规范》");
//        clickableUnit2.setNormalTextColor(ContextCompat.getColor(mContext, R.color.color_base));
//        clickableUnit2.setPressTextColor(ContextCompat.getColor(mContext, R.color.base_press_color));

        SimplifySpanBuild build = new SimplifySpanBuild(getContext(), contentTv, "已充分阅读并遵守");
        build.appendSpecialUnit(clickableUnit);
//        build.appendSpecialUnit(clickableUnit2);
        build.appendNormalText("确保您的个人的权益得到保护。");
        contentTv.setText(build.build());
    }

    @OnClick({R.id.cancelRtv, R.id.comfirmRtv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.cancelRtv:
                if (globalListener != null) {
                    globalListener.onCancelClick();
                }
                dismiss();
                break;
            case R.id.comfirmRtv:
                if (globalListener != null) {
                    globalListener.onConfirmClick();
                }
                dismiss();
                break;
        }
    }
}
